/*
*  Copyright 2019-2020 Zheng Jie
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package me.zhengjie.domain;

import lombok.Data;
import cn.hutool.core.bean.BeanUtil;
import io.swagger.annotations.ApiModelProperty;
import cn.hutool.core.bean.copier.CopyOptions;
import javax.persistence.*;
import javax.validation.constraints.*;
import java.math.BigDecimal;
import java.io.Serializable;

/**
* @website https://el-admin.vip
* @description /
* @author ...
* @date 2020-11-08
**/
@Entity
@Data
@Table(name="shuyi_address")
public class Address implements Serializable {

    private static final long serialVersionUID = -1211353148851833093L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "address_id")
    @ApiModelProperty(value = "地址编号，自增长")
    private Integer addressId;

    @Column(name = "reader_id",nullable = false)
    @NotNull
    @ApiModelProperty(value = "读者编号 ")
    private Integer readerId;

    @Column(name = "province",nullable = false)
    @NotBlank
    @ApiModelProperty(value = "省份(带“省”字) ")
    private String province;

    @Column(name = "city",nullable = false)
    @NotBlank
    @ApiModelProperty(value = "城市(带“市”字) ")
    private String city;

    @Column(name = "district",nullable = false)
    @NotBlank
    @ApiModelProperty(value = "区或县(带“区”或“县”字) ")
    private String district;

    @Column(name = "detail_address",nullable = false)
    @NotBlank
    @ApiModelProperty(value = "详细地址 ")
    private String detailAddress;

    @Column(name = "post")
    @ApiModelProperty(value = "邮政编码 ")
    private String post;

    @Column(name = "latitude",nullable = false)
    @NotNull
    @ApiModelProperty(value = "纬度 ")
    private BigDecimal latitude;

    @Column(name = "longitude",nullable = false)
    @NotNull
    @ApiModelProperty(value = "经度 ")
    private BigDecimal longitude;

    @Column(name = "is_main")
    @ApiModelProperty(value = "是否为默认地址,1为默认,0非默认 ")
    private Boolean isMain;

    @Column(name = "contact")
    @ApiModelProperty(value = "备注 ")
    private String contact;

    @Column(name = "phone_number")
    @ApiModelProperty(value = "电话号码 ")
    private String phoneNumber;

    @Column(name = "is_enable",nullable = false)
    @NotNull
    @ApiModelProperty(value = "是否启用 1启用 0未启用")
    private Boolean isEnable;

    public void copy(Address source){
        BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
    }
}